package com.sgb.kjwl.view.ui.activity.manage

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.sgb.kjwl.AppActivity
import com.sgb.kjwl.R
import com.sgb.kjwl.databinding.ActivityWebsiteOfferListBinding
import com.sgb.kjwl.view.ui.fragment.manage.DemandAnnouncementForWebsite

/**
 * 网站前台--报价列表
 */
const val KEY_SITE_TYPE = "key_site_type"
const val KEY_SITE_NO = "key_site_no"
const val KEY_IS_MYSELF = "key_is_myself"

class WebsiteOfferListActivity  : AppActivity() {
    private lateinit var mBinding : ActivityWebsiteOfferListBinding
    private var mSiteType = 1
    private var mSiteNO= ""
    private var mIsMySelf = false

    private var fragment : DemandAnnouncementForWebsite ?= null

    companion object{
        fun launch(context: Context, siteNo : String){
            launch(context, 1, siteNo, false)
        }

        fun launch(context: Context, siteType : Int, siteNo : String, isMySelf : Boolean){
            val intent = Intent()
            intent.setClass(context, WebsiteOfferListActivity::class.java)
            intent.putExtra(KEY_SITE_TYPE, siteType)
            intent.putExtra(KEY_SITE_NO, siteNo)
            intent.putExtra(KEY_IS_MYSELF, isMySelf)
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_website_offer_list)
        if (intent != null){
            mSiteType = intent.getIntExtra(KEY_SITE_TYPE, 1)
            mSiteNO = intent.getStringExtra(KEY_SITE_NO)
            mIsMySelf = intent.getBooleanExtra(KEY_IS_MYSELF, false)
        }
        if (savedInstanceState != null) {
            fragment = supportFragmentManager.findFragmentByTag(DemandAnnouncementForWebsite.TAG) as DemandAnnouncementForWebsite?
        } else {
            fragment = DemandAnnouncementForWebsite.newInstance(mSiteNO, mSiteType, mIsMySelf)
            supportFragmentManager.beginTransaction().replace(R.id.container, fragment!!, DemandAnnouncementForWebsite.TAG).commit()
        }
        mBinding.include.ivBack.setOnClickListener { finish() }
        mBinding.include.titleView.text = "报价列表"
    }
}